package com.shr.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shr.lease.model.entity.*;
import com.shr.lease.web.admin.mapper.*;
import com.shr.lease.web.admin.service.LeaseAgreementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shr.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.shr.lease.web.admin.vo.agreement.AgreementVo;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import static org.apache.coyote.http11.Constants.a;

/**
 * @author liubo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {

    @Resource
    private LeaseAgreementMapper leaseAgreementMapper;
    @Resource
    private ApartmentInfoMapper apartmentInfoMapper;
    @Resource
    private RoomInfoMapper roomInfoMapper;
    @Resource
    private PaymentTypeMapper paymentTypeMapper;
    @Resource
    private LeaseTermMapper leaseTermMapper;

    @Override
    public IPage<AgreementVo> pageAgreementVoByQuery(IPage<AgreementVo> page, AgreementQueryVo queryVo) {
        return leaseAgreementMapper.pageAgreementVoByQuery(page,queryVo);
    }

    @Override
    public AgreementVo getAgreementVoById(Long id) {
        //查询租约信息
        LeaseAgreement leaseAgreement = leaseAgreementMapper.selectById(id);
        //查询公寓信息
        Long apartmentId = leaseAgreement.getApartmentId();
        ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(apartmentId);
        //查询房间信息
        Long roomId = leaseAgreement.getRoomId();
        RoomInfo roomInfo = roomInfoMapper.selectById(roomId);
        //查询支付方式信息
        Long paymentTypeId = leaseAgreement.getPaymentTypeId();
        PaymentType paymentType = paymentTypeMapper.selectById(paymentTypeId);
        //查询租期信息
        Long leaseTermId = leaseAgreement.getLeaseTermId();
        LeaseTerm leaseTerm = leaseTermMapper.selectById(leaseTermId);
        AgreementVo agreementVo = AgreementVo.builder()
                .apartmentInfo(apartmentInfo)
                .roomInfo(roomInfo)
                .paymentType(paymentType)
                .leaseTerm(leaseTerm)
                .build();

        BeanUtils.copyProperties(leaseAgreement,agreementVo);
        return agreementVo;
    }
}




